package org.new9uy.tetris.util;

import java.awt.Color;
import java.awt.Frame;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.new9uy.tetris.GameConstants;

public class SwingUtils
{
    public static String showInputDialog(Frame parent, String title, String msg)
    {
        String s = (String) JOptionPane.showInputDialog(
                parent,
                msg,
                title,
                JOptionPane.PLAIN_MESSAGE);
        return s;
    }

    public static void infoMessage(Frame parent, String msg, String title)
    {
        JOptionPane.showMessageDialog(
                parent,
                msg,
                title,
                JOptionPane.PLAIN_MESSAGE,
                GameConstants.IMAGE_ICON);
    }

    public static JButton newDefaultButton(String text)
    {
        JButton b = new JButton(text);
        b.setVerticalTextPosition(JButton.CENTER);
        b.setHorizontalTextPosition(JButton.CENTER);
        b.setFont(GameConstants.FONT_DEFAULT_BUTTON);
        b.setIcon(GameConstants.IMAGE_DEFAULT_BUTTON);
        //b.setPressedIcon(pressedIcon); TODO
        b.setFocusPainted(false);
        b.setBorderPainted(false);
        b.setContentAreaFilled(false);
        return b;
    }

    public static JLabel newDefaultLabel(String text)
    {
        JLabel jl = new JLabel(text);
        jl.setForeground(Color.white);
        jl.setAlignmentX(JLabel.LEFT_ALIGNMENT);
        jl.setFont(GameConstants.FONT_DEFAULT_BUTTON);
        return jl;
    }

    public static void addBorder(JPanel p, String title)
    {
        p.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder(title),
                BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    }
}
